package com.tangtang.core.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.SortedSet;

/**
 *
 */
public class Tree<T> {

    private final List<Tree<T>> children = new ArrayList<Tree<T>>();

    private final Tree<T> parent;

    private final T value;

    Tree(final Tree<T> parent, final T value, final SortedMap<T, SortedSet<T>> childrenMap) {
        this.parent = parent;
        this.value = value;

        final SortedSet<T> list = childrenMap.get(value);
        if (list != null) {
            for (T child : list) {
                children.add(new Tree<T>(this, child, childrenMap));
            }
        }
    }

    public List<Tree<T>> getChildren() {
        return children;
    }

    public Tree<T> getParent() {
        return parent;
    }

    public T getValue() {
        return value;
    }

}
